﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using OgilvyOne.UKNow.BLL;
using ECCIT;
using OgilvyOne.UKNow.Model;

public partial class interactivedetail : System.Web.UI.Page
{
    private const string VIEWSTATE_WARMUPID = "wid";
    private const string VIEWSTATE_CURRPAGEIINDEX = "currPageIndex";
    private const string VIEWSTATE_SORTTYPE = "sortType";
    private const string VIEWSTATE_SORTDIRECT = "sortDirect";
    protected string count = "";
    protected string cuindex = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {


            if (Request.Params[VIEWSTATE_WARMUPID] != null)
            {
                ViewState[VIEWSTATE_WARMUPID] = int.Parse(Request.Params[VIEWSTATE_WARMUPID]);
                
            }
            else
            {
                Response.Redirect("interactivespace.aspx");
            }
            ViewState[VIEWSTATE_CURRPAGEIINDEX] = Request.Params[VIEWSTATE_CURRPAGEIINDEX];
            ViewState[VIEWSTATE_SORTTYPE] = Request.Params[VIEWSTATE_SORTTYPE];
            ViewState[VIEWSTATE_SORTDIRECT] = Request.Params[VIEWSTATE_SORTDIRECT];
        

            WarmupBLL bll = new WarmupBLL(2052);
            int pageSize = 1;
            PagingList models = bll.GetGetPublishedWarmupModels(int.Parse(Request.Params[VIEWSTATE_CURRPAGEIINDEX]), pageSize, ViewState[VIEWSTATE_SORTTYPE].ToString(), ViewState[VIEWSTATE_SORTDIRECT].ToString());
            count = models.Capacity.ToString();
            ViewState["counts"] = count;
            cuindex = (int.Parse(Request.Params[VIEWSTATE_CURRPAGEIINDEX]) + 1).ToString();
            if (cuindex == count && int.Parse( cuindex)> 1) tp_n.Visible = false;
            if ( int.Parse(cuindex) == 1) top_p.Visible = false;
        }
    }
    
    protected void top_p_Click(object sender, ImageClickEventArgs e)
    {
        if ((int.Parse(ViewState[VIEWSTATE_CURRPAGEIINDEX].ToString()) - 1) >= 0)
        {
            WarmupBLL bll = new WarmupBLL(2052);
            PagingList models = bll.GetGetPublishedWarmupModels(int.Parse(ViewState[VIEWSTATE_CURRPAGEIINDEX].ToString()) - 1, 1, ViewState[VIEWSTATE_SORTTYPE].ToString(), ViewState[VIEWSTATE_SORTDIRECT].ToString());
            string count = models.Capacity.ToString();
            string nextId = ((WarmupModel)models.List[0]).ID.ToString();
            Response.Redirect("interactivedetail.aspx?wid=" + nextId + "&currPageIndex=" + (int.Parse(ViewState[VIEWSTATE_CURRPAGEIINDEX].ToString()) - 1).ToString() + "&sortType=" + ViewState[VIEWSTATE_SORTTYPE] + "&sortDirect=" + ViewState[VIEWSTATE_SORTDIRECT]);
        }
        else if ((int.Parse(ViewState[VIEWSTATE_CURRPAGEIINDEX].ToString()) - 1)==0)
        {
            top_p.Visible = false;
        }

    }

    protected void tp_n_Click(object sender, ImageClickEventArgs e)
    {
        if ((int.Parse(ViewState[VIEWSTATE_CURRPAGEIINDEX].ToString())) < int.Parse(ViewState["counts"].ToString()) - 1)
        {
            WarmupBLL bll = new WarmupBLL(2052);
            int curr = int.Parse(ViewState[VIEWSTATE_CURRPAGEIINDEX].ToString()) + 1;
            PagingList models = bll.GetGetPublishedWarmupModels(curr, 1, ViewState[VIEWSTATE_SORTTYPE].ToString(), ViewState[VIEWSTATE_SORTDIRECT].ToString());
            string count = models.Capacity.ToString();
            string nextId = ((WarmupModel)models.List[0]).ID.ToString();
            Response.Redirect("interactivedetail.aspx?wid=" + nextId + "&currPageIndex=" + (int.Parse(ViewState[VIEWSTATE_CURRPAGEIINDEX].ToString()) + 1).ToString() + "&sortType=" + ViewState[VIEWSTATE_SORTTYPE] + "&sortDirect=" + ViewState[VIEWSTATE_SORTDIRECT]);

        }
        else
        {
            this.tp_n.Visible = false;  
        }
    }
}